from socket import *
import sys

#init
SERVER_IP = "127.0.0.1"
SERVER_PORT = 2333
SERVER_MAX_USER = 10
BUFFER = 1024
SERVER_ADDR = (SERVER_IP,SERVER_PORT)
client = socket(AF_INET,SOCK_STREAM)
client.connect(SERVER_ADDR)
is_connected = client.recv(BUFFER).decode()

if is_connected != "connected!":
    print("连接失败！")
    sys.exit()
print("服务器连接成功！")


def exchange_data(username,movement,contact):
    '''
    param username:发送数据的玩家用户名；movement：数据类型；contact：数据内容
    整理数据并发送数据到服务器进行处理,同时返回数据
    return 返回数据
    
    '''
    data = "{}#{}#{}".format(username,movement,contact)
    client.send(data.encode())
    return client.recv(BUFFER).decode()
